<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="./layui/css/layui.css" />
		<script type="text/javascript" src="./layui/layui.js" ></script>
	</head>
	
	<body>
		<!-- 编辑时 form表单 -->	
			<div class="layui-row"  id="updateHealthForm">
				<div class="layui-form">
					<div class="layui-form-item">
						<label class="layui-form-label">卫&nbsp;&nbsp;生&nbsp;&nbsp;ID:</label>
						<div class="layui-input-inline">
							<input type="number" name="hNub" id="hNub" placeholder="ID" class="layui-input" disabled="disabled"/>
						</div>
						
						<label class="layui-form-label">宿&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;舍:</label>
						<div class="layui-input-inline">
							<input type="number" name="dNub" id="dNub" placeholder="Dorm" class="layui-input" disabled="disabled"/>
						</div>
						
						<label class="layui-form-label">楼&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;层:</label>
						<div class="layui-input-inline">
							<input type="number" name="Floor_number" id="Floor_number" placeholder="Floor" class="layui-input" disabled="disabled"/>
						</div>
					</div>
					
					<div class="layui-form-item">
						<label class="layui-form-label">扣分明细:</label>
						<div class="layui-input-block">
							<input type="text" name="Deduction" id="Deduction" placeholder="Deduction" class="layui-input" required lay-verify="required"/>
						</div>
					</div>
					
					<div class="layui-form-item">
						<label class="layui-form-label">总扣分值:</label>
						<div class="layui-input-inline">
							<input type="number" name="The_value" id="The_value" placeholder="The_value" class="layui-input" required lay-verify="required"/>
						</div>
						
						<label class="layui-form-label">卫生类型:</label>
						<div class="layui-input-inline">
							<select name="health_type" id="health_type" required lay-verify="required">
								<option value=""></option>
								<option value="大扫除">大扫除</option>
								<option value="日常卫生">日常卫生</option>
							</select>
						</div>
						
						<label class="layui-form-label">卫生等级:</label>
						<div class="layui-input-inline">
							<select name="Grade" id="Grade" required lay-verify="required">
								<option value=""></option>
								<option value="A">A</option>
								<option value="B">B</option>
								<option value="C">C</option>
							</select>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注:</label>
						<div class="layui-input-block">
							<textarea name="Remarks" id="Remarks" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn" lay-submit lay-filter="update">更新</button>
						</div>
					</div>
				</div>
			</div>
			<script type="text/javascript">
			layui.use(['form','layer','jquery'],function(){
					var layer = layui.layer
					,$ = layui.$
					,form = layui.form;	
					//监听提交按钮
					form.on('submit(update)',function(data){
						//获取form提交值
						var obj = data.field;
						console.log(obj);
						obj = JSON.stringify(obj);
						//更新方法
						updateHealthInfo(obj);
						return false;//阻止form提交
					});
					//获取当前弹出层index
					var mainIndex = parent.layer.getFrameIndex(window.name);
					//编辑卫生信息
					function updateHealthInfo(obj){
						$.ajax({
							type:"post",
							url:"updateHealthInfoServlet",
							async:true,
							data:{obj:obj},
							success : function(date){//成功返回 1 /失败返回 0/object == null 返回 error
								console.log(date);
								if(date == 1){
									layer.open({
									time:2000,
									content:"更新成功，将在2s后关闭表单！",
									end:function(index){
										parent.layer.close(mainIndex);
											}
									});
								}else{
									layer.msg("更新失败");
								}
							},
							error : function(xhr, status, errMsg){
							console.log("status:"+status+"errMsg:"+errMsg);
							}
						});
					}
				});
				
				
			</script>
	</body>
</html>
